package demo1;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Create by jsonor 2017/09/14
 */
public class ConnectionPooledTest {

  public static void main(String[] args) {

    // 生成链接
    long startTime = System.currentTimeMillis();

    ConnectionPooled pooled = new ConnectionPooled();

    long createTime = System.currentTimeMillis();

    System.out.println("初始化消耗的时间 : " + (createTime - startTime) + "ms");
    Connection cn = pooled.getConnection();
    // 查询所消耗的时间
    PreparedStatement ps = null;
    try {
      ps = cn.prepareStatement("select * from user");
      ps.execute();

      long endTime = System.currentTimeMillis();

      System.out.println("总共消耗时间为：" + (endTime - createTime) + "ms");
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      if (ps != null) {
        try {
          ps.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }

      if (cn != null) {
        try {
          cn.close();
        } catch (SQLException e) {
          e.printStackTrace();
        }
      }
    }
  }
}
